import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.media.*;
import javafx.ext.swing.SwingButton;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Slider;
import javafx.scene.control.TextBox;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.layout.Flow;
import javafx.scene.Group;
import javafx.animation.Timeline;
import javafx.scene.control.Hyperlink;
import java.lang.System;
import javax.swing.JFileChooser;

var player:MyMediaPlayer = MyMediaPlayer {
    movieWidth: bind scene.width * 0.75;
    movieHeight: bind scene.height * 0.8;
}


def slider = Slider {
   max: 100
}

var controlsGroup:Group = Group {
    content: [
    	HBox {
			height: bind scene.width * 0.1
		   	content: [
		    	Label {text: "Volume"}
		        slider,
               	SwingButton {
                   	text: "Play"
                  	action: function() {
                   	    println("START VIDEO");
                      	player.play();
                   	}
               	},
   				SwingButton {
   					text: "Open"
   					action: function() {
   					  	println("OPEN FILE");
   					  	println(stage.width);
   					   	println(stage.height);
   					   	isVisible = not isVisible;
   					}
   				}
           	]
        }
	]
}


var fileBox:TextBox = TextBox{}
var isVisible:Boolean = false;

var openControlsGroup:Group = Group {
    content: [
		HBox {
  			height: bind scene.width * 0.1
   			visible: bind isVisible
   			content: [
   				Label { text: "URL/FILE: "},
   				fileBox,
   				SwingButton {
   					text: "searchFile"
   				   	action: function() {
   				  		println("Search File");
   				     	var chooser = new JFileChooser();
   				       	if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
   				         	fileBox.text = chooser.getSelectedFile().toURI().toString();
   				       	}
   				 	}
   				}
   			SwingButton {
   				text: "Load"
   				action: function() {
   				   	println("Load");
   				  	player.setVideo(fileBox.text);
   				   	isVisible = false;
   				}
   			}
   		]
	} 
    ]
}

def scene: Scene = Scene {
       content: 
          VBox {
                content: [
                	HBox {
                    	content: [
                    		VBox { 
                    		    width: bind scene.width * 0.8
                                content: [
	                                player,
		                            controlsGroup,
		                            openControlsGroup
	                            ]
                        	},
                            VBox {
                                width: bind scene.width * 0.2
                            	content: [
        	                     	Label {text: "Start:"}
        	                       	TextBox {} 
        	                     	Label {text: "Dauer"}
        	                       	TextBox {}  
   				                    SwingButton { 
   				                    	text: "Alpha"
   				                    	action: function() {
   				                    	    println("ALPHA");
   				                    	}
   				                    }
   				                    SwingButton{
   				                        text: "Wackeln"
   				                        action: function() {
   				                            println("WACKELN");
   				                        }
   				                    }  	                       	       	                       	
                                ]
                           	}
                       	]
					} 
				]
          }         
     }//Scene
 
def stage:Stage = Stage {
    title: "MediaPlayer MM1"
    width: bind stageWidth with inverse
    height: bind stageHeight with inverse
    scene: scene
}

var stageWidth = stage.width on replace {
	if (stageWidth < 640) stageWidth = 640;	
}

var stageHeight = stage.height on replace {
	if (stageHeight < 480) stageHeight = 480;	
}